package com.study.servlet;

import com.study.dao.CustomerDao;
import com.study.dao.impl.CustomerDaoImpl;
import com.study.model.Customer;
import com.study.util.GsonHelper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author WS
 */
@WebServlet(name = "addCustomer",urlPatterns = "/addCustomer")
public class CustomerAddServlet extends BaseServlet {
    private CustomerDao dao=new CustomerDaoImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 解决json中文乱码
        req.setCharacterEncoding("UTF-8");
        Customer update=new Customer();
        update.setAddress(req.getParameter("address"));
        update.setCardNo(req.getParameter("cardno"));
        update.setCardType(req.getParameter("cardtype"));
        update.setName(req.getParameter("name"));
        update.setNickname(req.getParameter("nickname"));
        update.setPwd(req.getParameter("pwd"));
        update.setSex(req.getParameter("sex"));
        update.setTel(req.getParameter("tel"));
        update.setBirthday(req.getParameter("birthday"));
        update.setWorkUnit(req.getParameter("workunit"));
        dao.add(update);
        req.getRequestDispatcher("/index.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req,resp);
        doGet(req, resp);
    }
}
